import { defineStore } from "pinia"
import { ref } from 'vue'

export const useUserInfoStore = defineStore('userInfo', () => {
  //1.定义用户信息
  const info = ref({})
  const userinfo = ref({
    avatar: '',
    nickName: '',
    realName: '',
    phone: '',
    identityNum: '',
    address: '',
  })
  //2.定义修改用户信息的方法
  const setInfo = (newInfo) => {
    info.value = newInfo
  }
  //3.定义清空用户信息的方法
  const removeInfo = () => {
    info.value = {}
  }
  const updateUserInfo = (newInfo) => {
    userinfo.value = newInfo;
  }

  return { info, setInfo, removeInfo, userinfo, updateUserInfo }
}, {
  persist: true
})


export const useUploadStore = defineStore('upload', {
  state: () => ({
    fileList: [],
    imgurl: '',
    uploadDisabled: false,
  }),
  actions: {
    addFile(file) {
      this.fileList.push(file);
      if (this.fileList.length >= 1) {
        this.uploadDisabled = true;
      }
    },
    removeFile() {
      this.fileList = [];
      this.uploadDisabled = false;
    },
    updateImgUrl(url) {
      this.imgurl = url;
    },
  },
});